package com.zds.hj.poseidon.biz.web;

import com.zds.boot.auth.annotation.ZdsController;
import com.zds.boot.auth.constants.DataAuthConstant;
import com.zds.boot.common.utils.Servlets;
import com.zds.boot.common.view.ViewResult;
import com.zds.boot.dispatch.api.DispatcherMainInterface;
import com.zds.boot.dispatch.context.ModelDispatchContext;
import com.zds.boot.dispatch.dto.BaseReqModel;
import com.zds.zly.common.utils.ViewResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @BelongsProject: zds-appcore
 * @BelongsPackage: com.zds.appcore.web.backend.iteration2.approve
 * @Author: jingjy
 * @CreateTime: 2019-07-27 13:12
 * @Description:
 */
@Slf4j
@ZdsController(value = "ApproveMainController", dataAuthBlock = DataAuthConstant.ZDS_CONTROLLER_AUTH_WILDCARD, dataAuthBlockCName = "融资端服务调度引擎服务")
@RequestMapping(value = "/zscms/hpp/approve")
public class ApproveMainController {

    @Resource
    private DispatcherMainInterface dispatcherMainInterface;


    /**
     * 执行
     */
    @RequestMapping(value = "/doSubmit.json", method = RequestMethod.POST)
    public ViewResult doSubmit(@RequestBody BaseReqModel baseReqModel, HttpServletRequest request, HttpServletResponse response) {
        baseReqModel.setLocation(Servlets.getIpAddress(request));
        baseReqModel.setHttpServletRequest(request);
        baseReqModel.setHttpServletResponse(response);
        return ViewResultUtil.buildSuccess(dispatcherMainInterface.doExe(baseReqModel));
    }

    /**
     * 获取下一步执行的模块信息
     * @param baseReqModel
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/getStep.json", method = RequestMethod.POST)
    public ViewResult getNextStep(@RequestBody BaseReqModel baseReqModel, HttpServletRequest request, HttpServletResponse response) {
        baseReqModel.setLocation(Servlets.getIpAddress(request));
        baseReqModel.setHttpServletRequest(request);
        baseReqModel.setHttpServletResponse(response);
        // 首页点击下一步，不触发短信发送
        ModelDispatchContext.getContext().setPreTouch(1);
        return ViewResultUtil.buildSuccess(dispatcherMainInterface.getNextStep(baseReqModel));
    }

    /**
     * 重新执行预处理
     * @param baseReqModel
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/redoPreHanding.json", method = RequestMethod.POST)
    public ViewResult redoPreHanding(@RequestBody BaseReqModel baseReqModel, HttpServletRequest request, HttpServletResponse response) {
        baseReqModel.setLocation(Servlets.getIpAddress(request));
        baseReqModel.setHttpServletRequest(request);
        baseReqModel.setHttpServletResponse(response);
        return ViewResultUtil.buildSuccess(dispatcherMainInterface.redoPreHanding(baseReqModel));
    }


    /**
     * 回显模块数据
     * @param baseReqModel
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/echoDetail.json")
    public ViewResult echoDetail(@RequestBody BaseReqModel baseReqModel, HttpServletRequest request, HttpServletResponse response) {
        baseReqModel.setLocation(Servlets.getIpAddress(request));
        baseReqModel.setHttpServletRequest(request);
        baseReqModel.setHttpServletResponse(response);
        return ViewResultUtil.buildSuccess(dispatcherMainInterface.echoDetail(baseReqModel));
    }

    /**
     * 回显模块数据List
     * @param baseReqModel
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/echoList.json")
    public ViewResult echoList(@RequestBody BaseReqModel baseReqModel, HttpServletRequest request, HttpServletResponse response) {
        baseReqModel.setLocation(Servlets.getIpAddress(request));
        baseReqModel.setHttpServletRequest(request);
        baseReqModel.setHttpServletResponse(response);
        return ViewResultUtil.buildSuccess(dispatcherMainInterface.echoList(baseReqModel));
    }

    /**
     * 调用模块的分段提交方法
     * @param baseReqModel
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/doSection.json", method = RequestMethod.POST)
    public ViewResult doSection(@RequestPart BaseReqModel baseReqModel, HttpServletRequest request, HttpServletResponse response) {
        baseReqModel.setLocation(Servlets.getIpAddress(request));
        baseReqModel.setHttpServletRequest(request);
        baseReqModel.setHttpServletResponse(response);
        return ViewResultUtil.buildSuccess(dispatcherMainInterface.doSection(baseReqModel));
    }

}
